﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using ModuleDALCore;
using DTO;

namespace DAL
{
	public class LOAINHAPDAO:DALBase
	{
		public LOAINHAPDAO()
		{
			this.OpenConnect();
		}
		private DataTable dt;
		private string _SpName;

		public string SpName
		{
			get { return "SPLOAINHAP"; }
			set { _SpName = value; }
		}

		public List<LOAINHAP> getListLoainhaps()
		{
			List<LOAINHAP> ctr = new List<LOAINHAP>();
			dt = new DataTable();

			try
			{
				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new LOAINHAP(), null), ConvertClassToArray.GetValues(new LOAINHAP(), 0));
				ctr = (List<LOAINHAP>)ConvertDatatableToList.ConvertTo<LOAINHAP>(dt);
			}

			catch { return null; }

			return ctr;
		}

		public DataTable getListLoainhap()
		{
			dt = new DataTable();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new LOAINHAP(), null), ConvertClassToArray.GetValues(new LOAINHAP(), 0));
				return dt;
			}
			catch { return null; }
		}

		public bool INSERT(LOAINHAP ln)
		{
			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(ln, null), ConvertClassToArray.GetValues(ln, 1)) == 1);
			}
			catch { return false; }
		}
		public bool UPDATE(LOAINHAP ln)
		{
			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(ln, null), ConvertClassToArray.GetValues(ln, 2)) == 1);
			}
			catch { return false; }
		}
		public bool DELETE(LOAINHAP ln)
		{
			try
			{
				return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(ln, null), ConvertClassToArray.GetValues(ln, 3)) == 1);
			}
			catch { return false; }
		}
	}
}